define([], function() {
    var app = angular.module("App.home");
    app.controller("projects.detail.prjDeleteCtrl", ["$scope", "$state", "curPrj", "showInfoModal", "showMsg", "$timeout", "Project", function($scope, $state, curPrj, showInfoModal, showMsg, $timeout, Project) {

        $scope.curPrj = curPrj;

        $scope.confirm = function() {
            showInfoModal({
                title: curPrj.name,
                content: '你正在删除' + curPrj.name + '项目.数据一旦删除就不可恢复,确认删除吗?',
                button: 2,
                onConfirm: function() {
                    curPrj.delete().then(function() {
                        //成功
                        $timeout(function() {
                            showMsg('删除成功', 'info');
                            Project.cityList.length = 0;
                            Project.getAllCityList().then(function() {
                                $state.transitionTo("projects", {}, {
                                    reload: true,
                                    inherit: false,
                                    notify: true
                                });
                            });
                        }, 1000);
                    }, function() {
                        $timeout(function() {
                            showMsg('删除发生错误', 'alert');
                        }, 1000);
                    });
                }
            });
        };
    }]);
});
